package training_process.TraningI_III;

/**
 * Author by KyrieC
 * Created by sheting on 2023/11/21
 */
public class Equation {
    private int lNum;   // 左边的数字
    private int rNum;   // 右边的数字
    private OP op;      // 运算符
    private int ans;    // 答案

    /**
     * 传入两个数字和运算符得到答案 ans
     * @param lNum
     * @param rNum
     * @param op
     */
    public Equation(int lNum, int rNum, OP op) {
        this.lNum = lNum;
        this.rNum = rNum;
        this.op = op;
        if (OP.ADD==op) {
            this.ans = lNum + rNum;
        } else if (OP.SUB==op) {
            this.ans = lNum - rNum;
        }
    }

    /**
     * 格式化输出
     * @return 格式规整的带有答案的计算式
     */
    @Override
    public String toString() {
        return String.format("%3d %s %-3d = %3d", lNum, OP.ADD==op?"+":"-", rNum, ans);
    }
}
